package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishVO;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: SetmealController
 * Description:
 *
 * @Author: Jdz
 * @Create: 2024/1/25 - 15:20
 */
@RequestMapping("/admin/setmeal")
@Slf4j
@RestController
@RequiredArgsConstructor
@Api(tags = "套餐相关接口")
public class SetmealController {

    private final SetmealService setmealService;

    @PostMapping
    @ApiOperation("新增套餐")
    public Result save(@RequestBody SetmealDTO setmealDTO) {
        return setmealService.saveWithDish(setmealDTO);
    }

    @GetMapping("/page")
    @ApiOperation("分页查询")
    public Result<PageResult> page(SetmealPageQueryDTO pageQueryDTO) {
        return setmealService.pageQuery(pageQueryDTO);
    }

    @DeleteMapping
    @ApiOperation("批量删除")
    public Result delete(@RequestParam List<Long> ids) {
        return setmealService.deleteBatch(ids);
    }

    @PostMapping("/status/{status}")
    @ApiOperation("启用禁用")
    public Result startOrStop(@PathVariable("status") Integer status, @RequestParam Long id) {
        return setmealService.startOrStop(status, id);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询套餐")
    public Result<SetmealVO> getById(@PathVariable Long id) {
        return setmealService.getByIdWithDish(id);
    }

    @PutMapping
    @ApiOperation("修改套餐")
    public Result update(@RequestBody SetmealDTO setmealDTO) {
        return setmealService.update(setmealDTO);
    }
}
